package excel.XlsCheckboxRead;

import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * java使用POI识别excel的复选框插件
 * https://blog.csdn.net/weixin_42683134/article/details/105952546
 * https://www.codenong.com/cs105952546/
 * <p>
 * POI通过继承HSSFListener类来解决Excel2003文件 https://blog.csdn.net/csl12919/article/details/131770944
 * POI如何解析出excel 中复选框是否被选中 https://blog.csdn.net/qq_29832217/article/details/104413475
 */
public class ExcelObject {

    private static final String Workbook = "Workbook";

    public static void main(String[] args) {
        //此处为我使用的一个线程用来存储每次复选框的识别列表（目前不需要）
        ObjectList.setCurrentFlag(new ArrayList());
        System.out.println("ReadCheckbox");
        readCheckbox("");
    }

    public static void readCheckbox(String path) {

        try (FileInputStream file = new FileInputStream(new File(path));
             POIFSFileSystem poifs = new POIFSFileSystem(file);
             InputStream istream = poifs.createDocumentInputStream(Workbook);
        ) {
            // https://vimsky.com/examples/detail/java-class-org.apache.poi.hssf.eventusermodel.HSSFRequest.html
            HSSFRequest req = new HSSFRequest();
            req.addListenerForAllRecords(new EventExample());
            HSSFEventFactory factory = new HSSFEventFactory();
            factory.processEvents(req, istream);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
